package com.thread.exeutor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * <p>
 *
 * </p>
 *
 * @author qingshan
 * @since 2020-11-28 10:56
 */
public class FixedThreadDemo1 {

//    public static ExecutorService servicePool = Executors.newFixedThreadPool(10);

    public static ExecutorService servicePool = Executors.newCachedThreadPool();

    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getName() + Thread.currentThread().getId());
        servicePool.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(6000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("后" + Thread.currentThread().getName() + Thread.currentThread().getId());
            }
        });
        servicePool.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("中" + Thread.currentThread().getName() + Thread.currentThread().getId());
            }
        });
        servicePool.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("前" + Thread.currentThread().getName() + Thread.currentThread().getId());
            }
        });
        System.out.println("FixedThreadDemo1.main");
    }
}
